<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>


    <style type="text/css">
        .search_input {
            overflow: visible;
            background-color: #FFFFFF;
            background-image: none;
            border: 1px solid #e5e6e7;
            border-radius: 1px;
            color: inherit;
            display: block;
            padding: 6px 12px;
            transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
        }
    </style>
</head>

<body>


<div class="breadcome-area">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="breadcome-list single-page-breadcome">
                    <div class="row">

                        <form id="searchForm">
                            <div class="col-lg-2 col-md-2 col-sm-2">

                                <input type="text" name="problemInfo" placeholder="请输入问题描述"
                                       class="search-int form-control">

                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2">
                                <input type="text" name="trainNo" placeholder="请输入机车编号"
                                       class="search-int form-control">
                            </div>


                        </form>
                        <div class="col-lg-2 col-md-2 col-sm-2">
                            <button class="btn btn-primary" onclick="operation.searchForm()">查询</button>
                            <!--
                                                                        <a href="javascript:void(0)" onclick="operation.searchForm()"><i class="fa fa-search"></i></a>
                            -->
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="mg-b-15">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="product-status-wrap drp-lst">
                    <h4>提交问题单</h4>
                    <div class="add-product">
                        <a href="#" onclick="operation.addWindow()">添加</a>
                    </div>
                    <div class="asset-inner">

                        <table id="dg"></table>


                    </div>


                </div>
            </div>
        </div>
    </div>
</div>


<!-- 第一个model 开始 -->
<div id="setFormModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keybord="false">
    <div class="modal-dialog" style="width:700px">
        <div class="modal-content">
            <div class="modal-header">
                编辑
            </div>
            <!-- modal-body 开始 -->
            <div class="modal-body">
                <form id="setFormId" class="form-horizontal" enctype="multipart/form-data">
                    <input type="hidden" name="id">

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="trainInfoId">机车</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="trainInfoId" name="trainInfoId"
                                    placeholder="请输入机车"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="problemType">问题类型</label>
                        <div class="col-sm-8">
                            <select class="form-control" name="problemType" placeholder="请输入问题类型">
                                <option value="">--请选择--</option>
                                <option value="钣金">钣金</option>
                                <option value="喷漆">喷漆</option>
                                <option value="配件">配件</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="problemInfo">问题描述</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" name="problemInfo" placeholder="请输入问题描述"></textarea>
                        </div>
                    </div>


                </form>
            </div>
            <!-- modal-body 结束 -->
            <div class="modal-footer">
                <button id="add_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.addForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="edit_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.editForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="delete_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.closeMoal()">
                    <span class="glyphicon glyphicon-remove"></span>关闭
                </button>
            </div>

        </div>
    </div>
</div>
<!-- 第一个model 结束 -->

<!-- Page-Level Scripts -->
<script type="text/javascript" th:inline="none">
    getZcxNormalTrainInfoList("trainInfoId");
    var operation = {
        searchForm: function () {
            $('#dg').bootstrapTable("refresh");
        },
        //弹出添加页面
        addWindow: function () {
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 1);

        },
        //添加表单
        addForm: function () {
            $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");

                temp.userId = $("#userId").val();
                $.post("/ZcxProblem/insertZcxProblem", temp, function (data) {

                    $("#dg").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setFormId').data('bootstrapValidator').resetForm(true);
                    $('#setFormId')[0].reset();
                    $('#setFormModal').modal('hide');
                });
            }

        },
        //弹出修改页面
        editWindow: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            setForm("#setFormId", row);
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 0);

        },
        //修改表单
        editForm: function () {
            var validate = $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");
                $.post("/ZcxProblem/updateZcxProblem", temp, function (data) {

                    $("#dg").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setFormId').data('bootstrapValidator').resetForm(true);
                    $('#setFormId')[0].reset();
                    $('#setFormModal').modal('hide');
                });
            }

        },
        //删除表单
        deleteFrom: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            bootbox.confirm({
                size: "small",
                title: "提示",
                message: "确认删除这条数据吗？",
                callback: function (result) {
                    if (result) {
                        $.post("/ZcxProblem/deleteZcxProblem", {id: row.id}, function (data) {

                            $("#dg").bootstrapTable("refresh");
                            message.alert(data.showInfo);

                        });

                    }
                }
            });


        },
        //关闭页面
        closeMoal: function () {
            $('#setFormId').data('bootstrapValidator').resetForm(true);
            //$('#setFormId').reset();
            $('#setFormModal').modal('hide');
        },
        //导出
        exportFile: function () {


        },
        //审核
        audit: function () {


        },


    }


    $(function () {
        //表格格式化
        var fmt = {
            queryParams: function (params) {
                var temp = getFormJson("searchForm");
                temp.rows = params.limit;
                temp.userId = $("#userId").val();
                temp.currentPage = (params.offset / params.limit) + 1;
                return temp;

            },
            setTime: function (value, row, index) {

                return formatTimeYMDhms(value);  //转成年月日时分秒
            },
            setOpt: function (value, row, index) {
                var html = '';
                /* '<button class="btn-white btn btn-xs">查看</button>'+ */
                if (row.problemAudit == "待审核") {

                    // html += '<button id="edit_btn" class="btn btn-outline-secondary btn-sm"  onclick="operation.editWindow('+index+')">编辑</button>';
                    // html +='<button class="btn btn-outline-secondary btn-sm"  onclick="operation.deleteFrom('+index+')">删除</button>';

                }

                return html;
            },
            setActImgUrl: function (value, row, index) {
                return '<img src="/TBook/queryPic?id=' + row.id + '" style="width:100px;heigth:100px"></img>';
            },
            setBorrow: function (value, row, index) {
                var htm = "";
                if (row.borrow == 0) {
                    htm = "未借阅";
                }
                if (row.borrow == 1) {
                    htm = "<span style='color:red;'>已借阅</span>";
                }
                return htm;
            },
        }

        var columns = [[

            {
                field: 'id',
                title: 'id',
                width: 10,
                align: 'center',
                visible: false
            },

            {title: '问题类型', field: 'problemType', align: 'center', valign: 'middle', visible: true},
            {title: '提交人', field: 'name', align: 'center', valign: 'middle', visible: true},
            {title: '问题描述', field: 'problemInfo', align: 'center', valign: 'middle', visible: true},
            {title: '机车', field: 'trainNo', align: 'center', valign: 'middle', visible: true},

            {title: '提交人', field: 'userId', align: 'center', valign: 'middle', visible: false},
            /*{title: '解决状态', field: 'problemStatus', align: 'center', valign: 'middle',visible:true},*/
            {title: '审核状态', field: 'problemAudit', align: 'center', valign: 'middle', visible: true},
            {title: '提交时间', field: 'createTime', align: 'center', valign: 'middle', visible: true},
            {title: '火车', field: 'trainInfoId', align: 'center', valign: 'middle', visible: false},
            {title: '操作', field: 'opt', align: 'center', valign: 'middle', visible: true, formatter: fmt.setOpt},


        ]];


        $('#dg').bootstrapTable({
            url: "/ZcxProblem/query",
            sidePagination: "server",
            queryParams: fmt.queryParams,
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            pagination: true,
            pageNumber: 1,
            pageSize: 10,
            pageList: [10, 25, 50, 100],
            //search:true,
            clickToSelect: true,
            singleSelect: true,
            toolbar: '#toolbar',
            columns: columns,
        })

    });


    $(function () {
        $("#setFormId").bootstrapValidator({
            /* live:'disabled',
            excluded:[':disabled'],
            feedbackIcons: {
        　　　　　　　　valid: 'glyphicon glyphicon-ok',
        　　　　　　　　invalid: 'glyphicon glyphicon-remove',
        　　　　　　　　validating: 'glyphicon glyphicon-refresh'
    　　　　　   },*/
            fields: {


                problemType: {
                    validators: {
                        notEmpty: {
                            message: "问题类型不能为空!",
                        },
                    }

                },


                problemInfo: {
                    validators: {
                        notEmpty: {
                            message: "问题描述不能为空!",
                        },
                    }

                },


                userId: {
                    validators: {
                        notEmpty: {
                            message: "提交人不能为空!",
                        },
                    }

                },


                problemStatus: {
                    validators: {
                        notEmpty: {
                            message: "解决状态不能为空!",
                        },
                    }

                },


                problemAudit: {
                    validators: {
                        notEmpty: {
                            message: "审核不能为空!",
                        },
                    }

                },


                createTime: {
                    validators: {
                        notEmpty: {
                            message: "创建时间不能为空!",
                        },
                    }

                },


                trainInfoId: {
                    validators: {
                        notEmpty: {
                            message: "火车不能为空!",
                        },
                    }

                },


            }

        });


    })


</script>

</body>

</html>
